#!/bin/bash
# Copyright (c) 2024 maminjie <canpool@163.com>
# SPDX-License-Identifier: MulanPSL-2.0

HOME_DIR=$(dirname $(readlink -f "$0"))
CUR_DIR=$(pwd)
ISO_DIR="$(realpath $HOME_DIR/../iso)"

cd $ISO_DIR
[ -d "oemaker" ] && rm -rf oemaker
git clone https://gitee.com/src-openeuler/oemaker.git
cd oemaker
OE_VERS=$(git branch -a | grep openEuler | awk -F '/' '{print $NF}' | grep -E "^openEuler.*[1-9S]$")
OE_ARCHS="x86_64 aarch64"

for oe_ver in $OE_VERS; do
    git checkout $oe_ver
    oe_dir=$ISO_DIR/$oe_ver
    mkdir -p $oe_dir
    if [ -f rpmlist.xml ]; then
        cp rpmlist.xml $oe_dir
    fi
    for oe_arch in $OE_ARCHS; do
        normal_xml="normal_${oe_arch}.xml"
        if [ -f "$normal_xml" ]; then
            arch_dir=$oe_dir/$oe_arch
            mkdir -p $arch_dir
            cp $normal_xml $arch_dir/normal.xml
        fi
    done
done

cd $ISO_DIR
[ -d "oemaker" ] && rm -rf oemaker

cd $CUR_DIR
